import { MockMethod } from 'vite-plugin-mock'

function createUserList() {
  return [
    {
      userId: 1,
      photo:
        'https://cn.bing.com/images/search?q=%e5%a4%b4%e5%83%8f&id=047C00A7AC1FB84D922FD648A58C6C401BFB7EB1&FORM=IQFRBA',
      username: 'admin',
      password: '123456',
      email: '2946021889@qq.com',
      roleCode: 'admin',
      managerName: '小明',
      token: 'Admin Token'
    }
  ]
}
export default [
  {
    url: '/mock/admin/Login/login', // 注意，这里只能是string格式
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body
      const checkUser = createUserList().find(
        item => item.username === username && item.password === password
      )
      if (!checkUser) {
        return { code: 201, data: { message: '账号或者密码不正确' } }
      }
      const { token } = checkUser
      return { code: 200, data: { token } }
    }
  },
  //getUserInfo
  {
    url: '/mock/admin/User/info', // 注意，这里只能是string格式
    method: 'post',
    response: req => {
      const token = req.headers.Authorization
      const checkUser = createUserList().find(item => item.token === token)
      if (!checkUser) {
        return { code: 201, data: { message: '获取用户信息失败' } }
      }
      return { code: 200, data: { checkUser } }
    }
  }
] as MockMethod[] // 这里其实就是定义数据格式的，不了解的同学可以参考typescript的官方文档
